/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import interfaces.UserProjectInterface;
import java.io.Serializable;
import java.util.Date;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import org.jboss.logging.Logger;

/**
 *
 * @author Thibault
 */
@Singleton
@Startup
public class DataSetCreator implements Serializable {

    @EJB
    UserProjectInterface userEJB;

    @PostConstruct
    public void postConstruct() {
        Logger.getLogger(DataSetCreator.class).info("DataSet creation begin.");
        this.createAdmin();
        this.createFirstUser();
        this.createSecondUser();
        Logger.getLogger(DataSetCreator.class).info("DataSet creation finished.");
    }

    private void createAdmin() {
        UserProject up = new UserProject("Admin", "Admin", "admin.admin@mail.com", "admin");
        userEJB.createUserProject(up);
    }

    private void createFirstUser() {
        UserProject up = new UserProject("Klein", "Thibault", "klein.thib@gmail.com", "klethi");
        up.getAdresses().add(new Address("rue de l'église", "Altrippe", 57660, 9, up));
        up.getArticles().add(new Article("Xbox", "Console Xbox 360 neuve", 150, new Date("2013/2/2"), up));
        up.getArticles().add(new Article("PC", "PC de bureau", 100, new Date("2013/2/1"), up));
        up.getArticles().get(0).getCategories().add(Category.Multimedia);
        up.getArticles().get(1).getCategories().add(Category.Multimedia);
        up.getArticles().get(1).setArticleState(ArticleState.sent);
        userEJB.createUserProject(up);
    }

    private void createSecondUser() {
        UserProject up = new UserProject("Flaus", "Claudia", "flaus.claudia@gmail.com", "flacla");
        up.getAdresses().add(new Address("rue d'éetzling", "Altrippe", 57460, 9, up));
        up.getArticles().add(new Article("Fiat 500", "Fiat 500 très bonne état", 5000, new Date("2013/2/1"), up));
        up.getArticles().get(0).getCategories().add(Category.Vehicle);
        up.getArticles().add(new Article("Appartement F2", "Nancy", 700, new Date("2013/2/5"), up));
        up.getArticles().get(1).getCategories().add(Category.Immovable);
        up.getArticles().add(new Article("JEU Skyrim", "Jeu de Xbox", 30, new Date("2013/2/7"), up));
        up.getArticles().get(2).getCategories().add(Category.Multimedia);
        up.getArticles().get(2).getBiddingHistory().add(new Bid(userEJB.findById(1), up.getArticles().get(2), new Date("2013/1/30"), 30));
        up.getArticles().get(2).getBiddingHistory().add(new Bid(userEJB.findById(2), up.getArticles().get(2), new Date("2013/1/31"), 35));
        userEJB.createUserProject(up);
    }
}
